export default function () {
    return function (blob: Blob) {
        const fileReader = new FileReader();
        fileReader.readAsArrayBuffer(blob);

        return new Promise((res, rej) => {
            function success() {
                res(new Uint8Array(fileReader.result as ArrayBufferLike));
                removeEventListener();
            }

            function error(e) {
                rej(e);
                removeEventListener();
            }

            function removeEventListener() {
                fileReader.removeEventListener("load", success);
                fileReader.removeEventListener("error", error);
            }

            fileReader.addEventListener("load", success);
            fileReader.addEventListener("error", error);
        });
    };
}
